<?php
declare (strict_types = 1);

namespace app\middleware;

class AdminLoginCheck
{
    /**
     * 处理请求
     *
     * @param \think\Request $request
     * @param \Closure       $next
     * @return Response
     */
    public function handle($request, \Closure $next)
    {
        //也可以放在路由里面加中间件限制；这里放在配置文件middleware.php里面配置了
        $exceptUrl=["/admin/login","/admin/doLogin"];
        $url=$request->url();
        if(!in_array($url,$exceptUrl)){
            $login_user=session("admin_user");
            if(empty($login_user)){
                //没登录；
                return redirect('/admin/login');
            }
        }
        return $next($request);
    }
}
